package com.explorati.design_pattern.structural.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 课程目录列表继承目录组合
 * 
 * @author explorati
 *
 */
public class CourseCatalog extends CatalogComponent {

	// 集合存放目录列表
	private List<CatalogComponent> items = new ArrayList<CatalogComponent>();
	// 目录名称
	private String name;
	// 目录级别
	private Integer level;

	public CourseCatalog(String name, Integer level) {
		this.name = name;
		this.level = level;
	}

	@Override
	public void add(CatalogComponent catalogComponent) {
		items.add(catalogComponent);
	}

	public String getName() {
		return this.name;
	}

	@Override
	public void remove(CatalogComponent catalogComponent) {
		items.remove(catalogComponent);
	}

	@Override
	public void print() {
		System.out.println(this.name);
		for (CatalogComponent catalogComponent : items) {
			if (this.level != null) {
				for (int i = 0; i < this.level; i++) {
					System.out.print("       ");
				}
			}
			catalogComponent.print();
		}
	}

}
